﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication1
{
    class Controller
    {
        static Model db;

        public Controller()
        {
            db = Model.GetInstance();
        }

        public string StockUpdate(int orderNum, int prodCode, int amount, DateTime recieved, DateTime expired)
        {
            if (db.GetProductCode(orderNum) != prodCode)
            {
                return "code";
            }

            else if (db.GetAmount(orderNum) != amount)
            {
                db.InsertToStock(prodCode, orderNum, amount, recieved, expired);
                return "amount";
            }

            else
            {
                db.InsertToStock(prodCode, orderNum, amount, recieved, expired);
                return "ok";
            }
            
        }

        public string FindProdName(int code)
        {
            return db.GetNameByCode(code);
        }

        public string FindCustName(int ID)
        {
            return db.GetNameByID(ID);
        }

        public double FindPrice(int code)
        {
            return db.GetProductPrice(code);
        }

        public void AddShopping(int ID, int code, int amount, double cost)
        {
            db.InsertShopping(ID, code, amount, cost);
            db.UpdateProductStock(code, amount);
            db.UpdateCustDebt(ID, cost);
        }
    }
}
